#include "Components/InputComponent.hpp"
#include "Components/ICompositor.hpp"
#include "Components/Message.hpp"
#include "Utility/Singleton.hpp"
#include "Utility/String.hpp"

#include "SFML/Graphics/RenderWindow.hpp"

#include <iostream>

namespace Components
{
	InputComponent::InputComponent( ICompositor &comp )
		: compositor( comp ), renderWnd( *Utility::Singleton< sf::RenderWindow >::Get() )
	{
	}

	InputComponent::~InputComponent( void )
	{
	}

	void InputComponent::Update( void )
	{
		renderWnd.PeekEvent( evt );

		if ( evt.Type == sf::Event::KeyPressed )
		{
			compositor.SendMessage( *this, Message( "Input:KeyPressed", evt.Key.Code ) );
		}
		else if ( evt.Type == sf::Event::KeyReleased )
		{
			compositor.SendMessage( *this, Message( "Input:KeyReleased", evt.Key.Code ) );
		}
		else if ( evt.Type == sf::Event::MouseButtonPressed )
		{
			compositor.SendMessage( *this, Message( "Input:MousePressed", evt.MouseButton.Button ) );
		}
		else if ( evt.Type == sf::Event::MouseButtonReleased )
		{
			compositor.SendMessage( *this, Message( "Input:MouseReleased", evt.MouseButton.Button ) );
		}
	}
}